package com.ruoyi.vote.admin.controller;

import java.util.Arrays;

import com.ruoyi.vote.admin.domain.VoteSign;
import com.ruoyi.vote.admin.domain.bo.VoteExamineBo;
import com.ruoyi.vote.app.domain.request.VoteSignReq;
import lombok.RequiredArgsConstructor;

import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vote.admin.domain.vo.VoteSignVo;
import com.ruoyi.vote.admin.domain.bo.VoteSignBo;
import com.ruoyi.vote.admin.service.IVoteSignService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参赛选手管理
 *
 * @author 筑巢
 * @date 2023-07-17
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/vote/sign")
public class VoteSignController extends BaseController {

    private final IVoteSignService iVoteSignService;

    /**
     * 获取参赛选手列表
     */
    @SaCheckPermission("vote:sign:list")
    @GetMapping("/list")
    public TableDataInfo<VoteSignVo> list(VoteSignReq bo, PageQuery pageQuery) {
        pageQuery.setOrderByColumn("vs.create_time");
        pageQuery.setIsAsc("desc");
        return iVoteSignService.queryPageList(bo, pageQuery);
    }

    /**
     * 获取参赛选手详情
     *
     * @param id 主键
     */
    @SaCheckPermission("vote:sign:query")
    @GetMapping("/{id}")
    public R<VoteSignVo> getInfo(@NotNull(message = "选手编号不能为空") @PathVariable Long id) {
        return R.ok(iVoteSignService.queryById(id));
    }

    /**
     * 新增参赛选手
     */
    @SaCheckPermission("vote:sign:add")
    @Log(title = "参赛选手", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody VoteSignBo bo) {
        return toAjax(iVoteSignService.insertByBo(bo));
    }

    /**
     * 修改参赛选手
     */
    @SaCheckPermission("vote:sign:edit")
    @Log(title = "参赛选手", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody VoteSign voteSign) {
        return toAjax(iVoteSignService.updateByBo(voteSign));
    }

    /**
     * 删除参赛选手
     *
     * @param ids 主键串
     */
    @SaCheckPermission("vote:sign:remove")
    @Log(title = "参赛选手", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "参赛ID不能为空") @PathVariable Long[] ids) {
        return toAjax(iVoteSignService.deleteWithValidByIds(Arrays.asList(ids)));
    }

    /**
     * 审核按钮
     */
    @SaCheckPermission("vote:sign:examine")
    @Log(title = "参赛选手", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/sign-examine")
    public R<Void> signExamine(@Validated(AddGroup.class) @RequestBody VoteExamineBo bo) {
        return toAjax(iVoteSignService.signExamine(bo));
    }
}
